{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<style type="text/css">
.btn.min-width {min-width: 104px;}
.modal-body .radio-inline{ margin-top:0px;}
.input-group .input-group-addon{ border-left:0; border-right:0}
.input-group .input-group-addon:first-child{border-left: 1px solid #e7e7eb;}
.input-group .input-group-addon:last-child{border-right: 1px solid #e7e7eb;}
.input-group .input-group-btn .btn-danger{border-color: #c9302c;}
.multi-img-details .multi-item{height:auto;}
#member.multi-img-details .multi-item{text-align:center; max-width:100px;}
#member.multi-img-details .multi-item img{ max-width:90px; max-height:90px;}
#member.multi-img-details .multi-item .title{ overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
</style>
<link href="{$_W['siteroot']}web/resource/components/select2/select2.min.css" rel="stylesheet">
<div class="main" style="margin:0px;">
{if $op == 'entry'}
    <form id="dataform" action="" method="post" class="form-horizontal form">
        <div class="panel panel-default">
            <div class="panel-heading">
                核销设置
            </div>
            <div class="panel-body">
                    <div class="form-group">
                       <label class="col-xs-12 col-sm-3 col-md-2 control-label">核销关键字</label>
                       <div class="col-sm-9 col-xs-12">
                           <input type="text" name="keyword" class="form-control" value="{$set['content']}">
                           <span class="help-block">店员核销使用，如果不填写默认为核销，使用方法: 回复关键词后系统会提示输入核销码</span>
                       </div>
                   </div>
                   <div class="form-group">
                           <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                           <div class="col-sm-9 col-xs-12">
                                 <input type="submit" name="keysubmit" value="保存设置" class="btn btn-primary">
                                 <input type="hidden" name="token" value="{$_W['token']}" />
                           </div>
                    </div>
            </div>
        </div>
    </form>
{/if}
{if $op == 'store'}
	{if $opp=='post'}
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$item['id']}" />
        <div class='panel panel-default'>
            <div class='panel-heading'>
                核销场地设置
            </div>
            <div class='panel-body'>
                {if MERCHANTID}
                <input type="hidden"name="merchantid" class="form-control" value="{$merchant['id']}" />
                {else}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>所属主办方</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="merchantid" class="form-control s1">
                        {if !aide_ID}
                        <option value="0" {if empty($item['merchantid'])}selected="selected"{/if}>{$_W['_config']['sname']}</option>
                        {/if}
                        {loop $merchants $row}
                            <option value="{$row['id']}" {if $item['merchantid']==$row['id']}selected="selected"{/if}>{$row['name']}</option>
                        {/loop}
                        </select>
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 场地名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="storename" id="hexiaoname" class="form-control" value="{$item['storename']}" placeholder="例如：xx大厦"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">联系电话</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="tel" class="form-control" value="{$item['tel']}" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">营业时间</label>
                    <div class="col-xs-12 col-sm-9 col-md-8 col-lg-7 layui-input-block">
                        <div class="input-group clockpicker" data-placement="left" data-align="top" id='time_start' data-autoclose="true" style="text-align: center;width: 30%;float: left;">
                            <input type="text" name="registerdate[startTime]" class="form-control" value="{$item['storehours']['startTime']}">
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-time"></span>
                            </span>
                        </div>
                        <div class="input-group clockpicker" data-placement="left" data-align="top" id='time_end' data-autoclose="true" style="text-align: center;width: 30%;margin-left: 5%;float: left;">
                            <input type="text" name="registerdate[endTime]" class="form-control" value="{$item['storehours']['endTime']}">
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-time"></span>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">位置坐标</label>
                    <div class="col-xs-12 col-sm-8">
                    {php echo tpl_form_field_position('map',array('lng'=>$item['lng'],'lat'=>$item['lat'],'adinfo'=>$item['adinfo']))}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">详情地址</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="address" id="address" class="form-control" value="{$item['address']}" id="address"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='qiyongstatus' value=1 {if $item['status']==1}checked{/if} /> 启用
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='qiyongstatus' value=0 {if $item['status']==0}checked{/if} /> 禁用
                        </label>
                    </div>
                </div>
                      <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="hidden" name="op" value="{$op}" />
                            <input type="submit" name="storesubmit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                    </div>
            </div>
            </div>
        </div>

    </form>
	<script language='javascript'>
    require(['../../components/select2/select2.min'], function(){
        $(".s1").select2();
        $(".select2").css('width','100%');
    });
    $('form').submit(function(){
        if($(':input[name=storename]').isEmpty()){
            Tip.focus($(':input[name=storename]'),'请输入场地名称!');
            return false;
        }
        return true;
    })
    </script>
	{elseif $opp == 'display'}
         <div class='panel panel-default'>
                <div class='panel-heading'>
                    核销场地设置
                </div>
             <div class='panel-body'>
                <table class="table">
                    <thead>
                        <tr>
                            <th>所属主办方</th>
                            <th>场地名称</th>
                            <th>场地地址</th>
                            <th>场地电话</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {loop $list $row}
                        <tr>
                            <td>{if $row['merchant']['name']}{$row['merchant']['name']}{else}{$_W['_config']['sname']}{/if}</td>
                            <td>{$row['storename']}</td>
                            <td>{$row['address']}</td>
                               <td>{$row['tel']}</td>

                                     <td>
                                        {if $row['status']==1}
                                        <span class='label label-success'>启用</span>
                                        {else}
                                        <span class='label label-danger'>禁用</span>
                                        {/if}
                                    </td>
                            <td>
                             <a class='btn btn-default' href="{php echo web_url('application/hexiao/store', array('opp'=>'post','id' => $row['id']))}"><i class='fa fa-edit'></i></a>
                             <a class='btn btn-default'  href="{php echo web_url('application/hexiao/store', array('opp'=>'delete','id' => $row['id']))}" onclick="return confirm('确认删除此场地吗？');return false;"><i class='fa fa-remove'></i></a></td>
                        </tr>
                        {/loop}
                    </tbody>
                </table>
             </div>
               <div class='panel-footer'>
                     <a class='btn btn-default' href="{php echo web_url('application/hexiao/store', array('opp'=>'post'))}"><i class="fa fa-plus"></i> 添加新场地</a>
             </div>
         </div>
	{/if}
{/if}
{if $op == 'saler'}
	{if $opp == 'post'}
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class='panel panel-default'>
            <div class='panel-heading'>
                核销员设置
            </div>
			<div class='panel-body'>
            	{if MERCHANTID}
                <input type="hidden" name="merchantid" class="form-control" value="{$merchant['id']}" />
                {else}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>所属主办方{$item['merchantid']}</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="merchantid" class="form-control s2">
                        {if !aide_ID}
                        <option value="0" {if empty($saler['merchantid'])}selected="selected"{/if}>{$_W['_config']['sname']}</option>
                        {/if}
                        {loop $merchants $row}
                            <option value="{$row['id']}" {if $saler['merchantid']==$row['id']}selected="selected"{/if}>{$row['name']}</option>
                        {/loop}}
                        </select>
                    </div>
                </div>
                {/if}

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 选择核销员</label>
                    <div class="col-xs-12 col-sm-9">
                        <div class='input-group'>
                            <input type="text" name="saler" maxlength="30" value="" class="form-control" readonly placeholder="可指定多个核销员" />
                            <div class='input-group-btn'>
                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus1').modal();">选择核销员</button>
                                <button class="btn btn-danger" type="button" onclick="reset_admin();">重置</button>
                            </div>
                        </div>
                        <div class="input-group multi-img-details" id="member">
                            {loop $openids $openid}
                            {if !empty($openid)}
                            {php $member = getMember($openid)}
                            <div class="multi-item">
                            <img src="{$member['avatar']}" onerror="this.src='{$_W['siteroot']}web/resource/images/nopic.jpg'; this.title='图片未找到.'" class="img-responsive img-thumbnail">
                            <input type="hidden" name="openids[]" value="{$openid}">
                            <em class="close" title="删除核销员" onclick="deleteMultiImage(this)">×</em>
                            <p class="help-block title">{$member['nickname']}</p>
                            </div>
                            {/if}
                            {/loop}
                        </div>
                        <div id="modal-module-menus1"  class="modal fade" tabindex="-1">
                            <div class="modal-dialog" style='width: 660px;'>
                                <div class="modal-content">
                                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择核销员</h3></div>
                                    <div class="modal-body" >
                                        <div class="row">
                                            <div class="input-group">
                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd1" placeholder="请输入粉丝昵称或openid" />
                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>
                                            </div>
                                        </div>
                                        <div id="module-menus1" style="padding-top:5px;"></div>
                                    </div>
                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">核销场地选择</label>
                    <div class="col-sm-9 col-xs-12 chks">
                        <div class='input-group'>
                            <input type="text" name="saler" maxlength="30" value="{loop $salers $saler} {$saler['nickname']}; {/loop}" id="saler" class="form-control" readonly />
                            <div class='input-group-btn'>
                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus2').modal();">选择场地</button>
                            </div>
                        </div>

                        <div style="margin-top:.5em;" class="input-group multi-audio-details clear-fix" id='stores'>
                            {loop $stores $store}
                            <div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="{$store['id']}">
                                <div class="input-group">
                                    <input type="hidden" value="{$store['id']}" name="storeids[]">
                                    <input type="text" value="{$store['storename']}" readonly="" class="form-control">
                                    <div class="input-group-btn">
                                        <button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button>
                                    </div>
                                </div>
                            </div>
                            {/loop}
                        </div>
                        <span class='help-block'>如果不选择场地，则此核销员为全局核销员，所有场地的均可核销</span>
                        <div id="modal-module-menus2" class="modal fade" tabindex="-1">
                            <div class="modal-dialog" style='width: 660px;'>
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                        <h3>选择场地</h3></div>
                                    <div class="modal-body">
                                        <div class="row">
                                            <div class="input-group">
                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd2" placeholder="请输入场地名称" />
                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_stores();">搜索</button></span>
                                            </div>
                                        </div>
                                        <div id="module-menus2" style="padding-top:5px;"></div>
                                    </div>
                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class='radio-inline'>
                            <input type='radio' name='salerstatus' value=1 {if $saler['status']==1}checked{/if} /> 启用
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='salerstatus' value=0 {if $saler['status']==0}checked{/if} /> 禁用
                        </label>
                    </div>
                </div>

                   <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                            <input type="hidden" name="salerid" value="{$id}" />
                            <input type="hidden" name="op" value="{$op}" />
                            <input type="submit" name="salersubmit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                    </div>
            </div>
            </div>
        </div>
    </form>
	<script language='javascript'>
		require(['../../components/select2/select2.min'], function(){
			$(".s2").select2();
			$(".select2").css('width','100%');
		});
        $('form').submit(function () {
            if ($(':input[name=saler]').isEmpty()) {
                Tip.focus($(':input[name=saler]'), '请选择核销员!');
                return false;
            }
            return true;
        })
    </script>
    {elseif $opp == 'display'}
    <form action="" method="post" onsubmit="return formcheck(this)">
        <div class='panel panel-default'>
            <div class='panel-heading'>
                  核销员管理
            </div>
            <div class='panel-body'>
                <table class="table">
                    <thead>
                        <tr>
                            <th>所属主办方</th>
                            <th class="col-sm-4">核销员</th>
                            <th>所属场地</th>
                            <th>状态</th>
                            <th style="width:100px;">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {loop $list $row}
                        <tr>
                            <td>{if $row['merchant']['name']}{$row['merchant']['name']}{else}{$_W['_config']['sname']}{/if}</td>
                            <td><span class="line-feed">{$row['salername']}</span></td>
                            <td><span class="line-feed">{if empty($row['storename'])}全店核销{else}{$row['storename']}{/if}</span></td>
                            <td>
                                {if $row['status']==1}
                                <span class='label label-success'>启用</span>
                                {else}
                                <span class='label label-danger'>禁用</span>
                                {/if}
                            </td>
                            <td>
                                <a class='btn btn-default' href="{php echo web_url('application/hexiao/saler', array('opp'=>'post','id' => $row['id']))}"><i class='fa fa-edit'></i></a>
                                <a class='btn btn-default'  href="{php echo web_url('application/hexiao/saler', array('opp'=>'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此核销员吗？');return false;"><i class='fa fa-remove'></i></a>
                               </td>
                        </tr>
                        {/loop}
                    </tbody>
                </table>
            </div>
            <div class='panel-footer'>
                <a class='btn btn-default' href="{php echo web_url('application/hexiao/saler', array('opp'=>'post'))}"><i class="fa fa-plus"></i> 添加新核销员</a>
            </div>
        </div>
    </form>
	{/if}
    <script language='javascript'>
	    //选择会员
		function search_members() {
			if( $.trim($('#search-kwd1').val())==''){
				util.tips('请输入关键词');
				$('#search-kwd1').focus();
				return;
			}
			$("#module-menus1").html("正在搜索....")
			$.get("{php echo web_url('member/member/selectmember')}", {
				keyword: $.trim($('#search-kwd1').val())
			}, function(dat){
				$('#module-menus1').html(dat);
			});
		}
		function select_member(o) {
			var hh = '', istrue = true, modalobj = $('#modal-module-menus1');
			$("input[name='openids[]']").each(function(){
				if ($(this).val()==o.openid){
					util.tips('核销员不能重复');
					istrue = false;
					return false;
				}
			});
			if (!istrue) return false;
			hh += '<div class="multi-item"><img src="'+o.avatar+'" onerror="this.src=\''+"{$_W['siteroot']}"+'web/resource/images/nopic.jpg\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail">'
			+'	<input type="hidden" name="openids[]" value="'+o.openid+'">'
			+'	<em class="close" title="删除核销员" onclick="deleteMultiImage(this)">×</em>'
			+'	<p class="help-block title">'+o.nickname+'</p>'
			+'</div>';
			$("#member").append(hh);
			modalobj.modal('hide');
		}
		function reset_admin(){
			$("#member").html('');
		}
		function deleteMultiImage(obj){
			$(obj).parents(".multi-item").remove();
		}
		//选择场地
	    function search_stores() {
			var merchantid = $("select[name='merchantid']").val();
			$("#module-menus2").html("正在搜索....")
			$.get("{php echo web_url('application/hexiao/selectstore')}", {
				keyword: $.trim($('#search-kwd2').val()),merchantid: merchantid
			}, function(dat){
				$('#module-menus2').html(dat);
			});
		}
		function remove_store(obj){
	        var storeid = $(obj).closest('.multi-audio-item').attr('storeid');
	        	$('.multi-audio-item[storeid="' + storeid +'"]').remove();
		    }
		function select_store(o) {
            if($('.multi-audio-item[storeid="' + o.id +'"]').length>0){
                return;
            }
            var html ='<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="' + o.id +'">';
                html+='<div class="input-group">';
                html+='<input type="hidden" value="' + o.id +'" name="storeids[]">';
                html+='<input type="text" value="' + o.storename +'" readonly="" class="form-control">';
                html+='<div class="input-group-btn"><button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button></div>';
             	html+='</div></div>';
                $('#stores').append(html);
		}
	</script>
{/if}
</div>
{aide_template 'common/footer'}
